package com.ruoyi.project.men.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.men.domain.MenDungoudanaoDO;
import com.ruoyi.project.men.service.MenDungoudanaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 盾构大脑
 * 
 * @author long
 * @email 499626561@qq.com
 * @date 2020-12-25 10:28:26
 */
 
@Controller
@RequestMapping("/men/menDungoudanao")
public class MenDungoudanaoController extends BaseController {
	@Autowired
	private MenDungoudanaoService menDungoudanaoService;



	/**
	 * 查询盾构大脑列表
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menDungoudanao:list')")
	@GetMapping("/list")
	public TableDataInfo list(MenDungoudanaoDO menDungoudanao)
	{
		startPage();
		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(menDungoudanao);
		stringObjectMap.put("delFlag","0");
		stringObjectMap.put("sort","ca_at");
		stringObjectMap.put("order","desc");
		List<MenDungoudanaoDO> list = menDungoudanaoService.list(stringObjectMap);
		return getDataTable(list);
	}

	/**
	 * 导出盾构大脑列表
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menDungoudanao:export')")
	@Log(title = "盾构大脑", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(MenDungoudanaoDO menDungoudanao)
	{
		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(menDungoudanao);
		List<MenDungoudanaoDO> list = menDungoudanaoService.list(stringObjectMap);
		ExcelUtil<MenDungoudanaoDO> util = new ExcelUtil<MenDungoudanaoDO>(MenDungoudanaoDO.class);
		return util.exportExcel(list, "menDungoudanao");
	}

	/**
	 * 获取盾构大脑详细信息
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menDungoudanao:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") String id)
	{
		return AjaxResult.success(menDungoudanaoService.get(id));
	}

	/**
	 * 新增盾构大脑
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menDungoudanao:add')")
	@Log(title = "盾构大脑", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody MenDungoudanaoDO menDungoudanao)
	{
		menDungoudanao.setId(IdUtil.simpleUUID());
		menDungoudanao.setDelFlag(0);
		menDungoudanao.setCaAt(new Date());
		return toAjax(menDungoudanaoService.save(menDungoudanao));
	}

	/**
	 * 修改盾构大脑
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menDungoudanao:edit')")
	@Log(title = "盾构大脑", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody MenDungoudanaoDO menDungoudanao)
	{
		menDungoudanao.setUpAt(new Date());
		return toAjax(menDungoudanaoService.update(menDungoudanao));
	}

	/**
	 * 删除盾构大脑
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menDungoudanao:remove')")
	@Log(title = "盾构大脑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable String[] ids)
	{
		if(ids.length>0){
			for (String string : ids) {
				MenDungoudanaoDO menDungoudanaoDO = menDungoudanaoService.get(string);
				menDungoudanaoDO.setDelFlag(1);
				menDungoudanaoDO.setUpAt(new Date());
				menDungoudanaoService.update(menDungoudanaoDO);
			}
		}
		return toAjax(ids.length);
		//return toAjax(menDungoudanaoService.deleteMenDungoudanaoByIds(ids));
	}

	
}
